//
//  JKJMainViewController.m
//  jiukeji
//
//  Created by 小宇 on 2017/11/23.
//  Copyright © 2017年 小宇. All rights reserved.
//

#import "JKJMainViewController.h"
#import "JKJMainNaViViewController.h"
@interface JKJMainViewController ()

@end

@implementation JKJMainViewController

- (void)viewDidLoad {
    [super viewDidLoad];

	//1.添加子控制器
	[self addChildViewControllers];
}

//1.添加子控制器
- (void)addChildViewControllers
{


	//1.消息
	UINavigationController *messageVc = [self setupControlWithTitle:@"推荐" withImageName:@"tuijian" withClassName:@"JKJRecommendViewController"];

	//2.联系人
	UINavigationController *contactVc = [self setupControlWithTitle:@"新口子" withImageName:@"daikuan" withClassName:@"JKJNewincisionViewController"];

	//3.动态
	UINavigationController *qzoneVc = [self setupControlWithTitle:@"分类" withImageName:@"fenlei" withClassName:@"JKJClassificationViewController"];


	//4.设置
	UINavigationController *settingVc = [self setupControlWithTitle:@"我的" withImageName:@"wode" withClassName:@"JKJMineViewController"];


	//3.添加
	self.viewControllers = @[messageVc,contactVc,qzoneVc,settingVc];

}

//创建子控制器
- (UINavigationController *)setupControlWithTitle:(NSString *)title  withImageName:(NSString *)imageName withClassName:(NSString *)className
{

	//1.根据类名称 转成类
	Class class = NSClassFromString(className);


	//2.根据类创建对应的对象
	UIViewController *messageVc = [[class alloc]init];


	//抛出异常
	NSAssert([messageVc isKindOfClass:[UIViewController class]], @"%@的名字错了",className);



	//设置title ,image
	messageVc.title = title;
	messageVc.tabBarItem.image = [UIImage imageNamed:imageName];

	self.tabBar.tintColor = [UIColor redColor];
	//NSLog(@"str2:%@",str2);
//	messageVc.tabBarItem.selectedImage = [[UIImage imageNamed:[NSString stringWithFormat:@"red%@",imageName]] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];

	//2.包装nav
	JKJMainNaViViewController *navVc = [[JKJMainNaViViewController alloc] initWithRootViewController:messageVc];
	return navVc;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
